function [ output_args ] = testDelauney( input_args )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
    setEnv();
    videoDir = 'C:\Users\rniehaus\Documents\Elegans\Videos\Test Video 300 Frames\';
    identifier = 'tif';
    [video, nFrames, vidRows, vidCols] = loadVideo( 'SeparateImages', videoDir, identifier );
    for i = 140:140
        bwFrame = segWormVal(video(i).gdata);
        se = strel('disk',3);
        bwFrame= imclose(bwFrame,se);
        figure(1), imshow(bwFrame)
          
        [B,L,N,A] = bwboundaries(bwFrame);
        outerBoundary = B{1};
        
        d = 20;
        xOuter = vidRows - outerBoundary(:,1);
        yOuter = outerBoundary(:,2);
        
        %% inner boundary
        innerBoundaryCell = B(2);
        innerBoundaryMat = innerBoundaryCell{1};
        xInner = vidRows - innerBoundaryMat(:,1);
        yInner = innerBoundaryMat(:,2);
        
        figure(2)
        plot(xInner, yInner, 'r');
        hold on
        plot(xOuter, yOuter, 'b');
        
        %% Delaunay
        
        totalBoundary = [ [xInner;xOuter],[yInner;yOuter] ];
        tri = delaunay(totalBoundary(:,1), totalBoundary(:,2));
        triplot(tri, totalBoundary(:,1), totalBoundary(:,2));
%        
        indexHead = ismember(head, [xOuter,yOuter], 'rows');
        indexTail = ismember(head, [xOuter,yOuter], 'rows');
        
        %% Estimate of inner boundary
        
        %Sample the outer boundary
         index = 1:15:size(boundary,1);
         xSampled = x(index,:);
         ySampled = y(index,:);

       
        make_plot = 0;
        flag1 = 0;
       
        [x_inner, y_inner, ~, ~, R, unv, concavity, overlap]=parallel_curve(xSampled, ySampled, d, make_plot, flag1);
        
        figure(3);
        plot(x, y, 'b');
        
        
        x_inner= x_inner(1:4);
        y_inner = y_inner(1:4);
        xx= [x_inner(1):-1:x_inner(4)];
        yy = spline(x_inner,y_inner,[x_inner(1):-1:x_inner(4)]);
     
        figure(3)
        plot(x, y, 'b');
        hold on;
        plot(xx,yy);
        
         legend({'Curve', 'Inner Parallel', }, 'location', 'Best');

    % The axis scaling can be modified.
%     % axis equal makes the plots more realistic for geometric
%     % constructions.  if this is a problem, change to axis normal.
%     axis equal
%     % axis normal
%        
%         totalBoundary = [ [x_inner;x],[y_inner;y] ];
%         tri = delaunay(totalBoundary(:,1), totalBoundary(:,2));
%         triplot(tri, totalBoundary(:,1), totalBoundary(:,2));
%        
        
%         totalBoundary = [];
%         for i = 1:1:size(allBoundaries)
%             
%            totalBoundary = [totalBoundary;allBoundaries{i}];
% 
%         end
%         sampledBoundary =[];
%         for i = 1:1:size(totalBoundary)
%             
%           sampledBoundary = [sampledBoundary;totalBoundary(i)];
% 
%         end
%         tri = delaunay(totalBoundary(:,1), totalBoundary(:,2));
%         triplot(tri, totalBoundary(:,1), totalBoundary(:,2));
%         
% %         for i = 1:size(tri,1))
% %          
% %                 pointA = boundary(tri(i,1),:);
% %                 pointB = boundary(tri(i,2),:);
% %                 pointC = boundary(tri(i,3),:);
% %                 X(i) = round(pointA(1) - pointB(1))/2);
% %                 Y(i) = round(pointA(2) - pointB(2))/2);
% %         end
% %         IN = inpolygon(X,Y,boundary(:,1), boundary(:,2));
% 
%         
%         pause;
%     end
        
    
    
end

